<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>后台登陆</title>
    <link href="${applicationScope.basePath}/css/login3.css" rel="stylesheet">
</head>
<body>

<div class="login">
    <div class="message">二手交易平台-管理员登录</div>
    <div id="darkbannerwrap"></div>

    <form id="loginForm" action="${applicationScope.basePath}/admin/checkLogin" method="post">
        <input name="action" value="login" type="hidden">
        <input name="username" placeholder="用户名" required="required" type="text">
        <hr class="hr15">
        <input name="password" placeholder="密码" required="required" type="password">
        <hr class="hr15">
        <input name="checkCode" style="width:50%;" placeholder="验证码" required="required" type="text">
        <a href="javascript:;">
            <img id="check_code" style="float: right;margin-right: 30px;" src="${applicationScope.basePath}/admin/checkCode" onclick="refreshCode();" title="看不清点击刷新" alt=""/>
        </a>
        <hr class="hr15">
        <input value="登录" style="width:100%;" type="submit">
        <hr class="hr20">
<%--        帮助 <a onClick="alert('请联系管理员');">忘记密码</a>--%>
    </form>
</div>


<script src="${applicationScope.basePath}/js/jquery-3.4.1.min.js"></script>
<script src="${applicationScope.basePath}/js/jquery.form.min.js"></script>
<script src="${applicationScope.basePath}/js/bootstrap.js"></script>
<script>
    //切换验证码图片
    function refreshCode() {
        //获取验证码对象
        let code = document.getElementById("check_code");
        //设置其src属性，加上上时间戳
        code.src = "${applicationScope.basePath}/admin/checkCode?time=" + new Date().getTime();
    }
    /*提交表单*/
    $(function () {
        let flag = true;
        let options = {
            success: function (data) {
                if(!data.flag){
                    alert(data.errorMsg);
                    refreshCode();
                    flag = true;
                }else{
                    window.location.href ="${applicationScope.basePath}/admin/main";
                }
            }
        };
        if(flag){
            $("#loginForm").ajaxForm(options);
            flag = false;
        }
    });
</script>
</body>
</html>
